SQL : Keys
I was always told that the key ( dad joke?) to learning was to actively engagne in the information and constantly be analyzing how it all fits together. What im going to do is use my notes and write up a summary on here. My notes are just quick 3 word rambles so I dont think that would be useful for anyone. Plus I think rewriting them in a long-form way would help me with the retention.
Speaking of Key
Databases used for SQL utilize a primary key . The primary key is in the form of a column. The primary key is a way to uniquely mark each row or entry . There must be a primary key . There are different types of keys used for different functions.
- Surrogate Key - a type of primary key that is not mapped to anything .
- Natural Key - a key that comes “natural in the real world “ - aka SSN ,
- Foreign Key - a key that can be stored in another table . It is used to connect to another table . ( like the little connectors on top lego piece that connects to the bottom of a different lego piece )
- references a primary key of another table - so the foreign key in part of a table that has a different primary key
- Helps define the relationship between the tables
- there can be more than 1 foreign keys in a table
- Composite Key
- can be used in a situation where no one key can uniquely identify the row.
- ex. 2 John Smiths with idential information
- has 2 attributes ( aka columns) that are used to identify each row
- can be made up of foreign keys
- can be used in a situation where no one key can uniquely identify the row.
SQL Language
The language “dailects” can vary between systems depending on the differnt RDBMS - However concepts are the same they just have different implementations . A Query is a requst but more like a specfic set of instructions to tell the RDBMS what info you want.